package com.zhenyi.youqu.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.youqu.common.model.YqShopUser;
import com.zhenyi.youqu.admin.index.YQAdminController;

public class PermissionInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		try {
			YQAdminController c = (YQAdminController) controller;
			YqShopUser user = c.getShopUser();
			c.setAttr("hasPermission", new HasPermissionFreeMarkerMethod(user));
			c.setAttr("hasEditPermission", new HasEditPermissionFreeMarkerMethod(user, c));
		} catch (Exception e) {
			controller.setAttr("hasPermission", false);
			controller.setAttr("hasEditPermission", "disabled='disabled'");
		}
		inv.invoke();
	}

}
